package com.kyd.shopping.es.controller;

import com.kyd.shopping.es.domain.Product;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: TestUseEeController
 * Package: com.kyd.shopping.es.controller
 * Description:
 *
 * @Author ketty bluce
 * @Create 2022/12/8
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/test/es")
public class TestUseEsController {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;

    /**
     * 新增
     *
     * @return
     */
    @RequestMapping("/save")
    public Product save() {
        Product product = new Product();
        product.setId(2L);
        product.setTitle("华为手机");
        product.setCategory("手机");
        product.setPrice(2999.0);
        product.setImages("http://www.atguigu/hw.jpg");

        Product save = elasticsearchRestTemplate.save(product);

        return save;
    }

    //修改
    @RequestMapping("/update")
    public void update() {
        Product product = new Product();
        product.setId(1L);
        product.setTitle("小米 2 手机");
        product.setCategory("手机");
        product.setPrice(9999.0);
        product.setImages("http://www.atguigu/xm.jpg");
    }


    //删除
    @RequestMapping("/delete")
    public void delete() {
        Product product = new Product();
        product.setId(1L);
        elasticsearchRestTemplate.delete(product);
    }



}